<template>
	<view class="inquiry">
		<scroll-view scroll-y="true" style="width:100%;min-height: 750rpx;">
			<view class="h48 df ac bbf1" hover-class="none" :hover-stop-propagation="false">
				<span class="f14 cf5">*</span>
				<p class="f14 c28">需求说明</p>
			</view>
			<textarea class="db w100 h110 pt15 f14" @input="changeName" data-i="0" :value="info.spare_parts_name"
				placeholder-class="cc" placeholder="请填写零件名称、数量、材料、要求等信息"></textarea>
			<view class="mt15 df ac sb bbf1" style="padding-bottom:20rpx;">
				<image class="w166" src="https://cdn.xtwaixie.com/uploads/20240705/17201796166687dba074393.png"
					mode="widthFix" @tap="upImgArr" data-idx="0"></image>
				<image class="w166" src="https://cdn.xtwaixie.com/uploads/20240705/17201796166687dba0904a2.png"
					mode="widthFix" @tap="upFile" data-idx="0"></image>
			</view>
			<ul class="df ac fw mt15" v-if="info.drawing.length != 0">
				<block v-for="(item, index) in info.drawing" :key="index">
					<li class="mb8 mr8 img64 pr db">
						<image class="img64" referrerPolicy='no-referrer' :src="getImgSrc(item)" />
						<image class="img-del" src="https://wx.xtwaixie.com/img/del.png" @tap="onDel(index)"
							data-idx="1" />
					</li>
				</block>
			</ul>
			<view class="h44 mt8 bgcf7 df ac pd015" v-if="info.file_name.length != 0"
				v-for="(item, index) in info.file_name" :key="index">
				<image class="img16" src="https://wx.xtwaixie.com/img/file.png"></image>
				<p class="ml8 f14 c28 f1">{{ item.name }}</p>
				<image class="img16" src="https://wx.xtwaixie.com/img/del3.png" @tap="onDelFile(index)" data-idx="1"></image>
			</view>
			<view class="df ac h48 bbf1 mt10">
				<span class="f14 cf5">*</span>
				<p class="f14 c28 f1">联系信息</p>
				<ul class="df">
					<li class="df ac ml24" @tap.native="changeRadio(0)" data-i="4" data-act="0">
						<image class="img18" referrerPolicy='no-referrer'
							:src="info.is_quotation == 0 ? 'https://wx.xtwaixie.com/img/sel1.png' : 'https://wx.xtwaixie.com/img/sel2.png'"></image>
						<p class="f14 c28 ml8">直接联系</p>
					</li>
					<li class="df ac ml24" @tap.native="changeRadio(1)"
						data-i="4" data-act="1">
						<image class="img18" referrerPolicy='no-referrer'
							:src="info.is_quotation == 1 ? 'https://wx.xtwaixie.com/img/sel1.png' : 'https://wx.xtwaixie.com/img/sel2.png'"></image>
						<p class="f14 c28 ml8">先加微信</p>
					</li>
				</ul>
			</view>
			<view v-if="info.file_name.length != 0 || info.drawing.length != 0"  style="height:200rpx;"></view>
		</scroll-view>
		<view class="pd15 mt15" hover-class="none" :hover-stop-propagation="false">
			<button class="sub2" @tap="onSub"> 发送询价 </button>
		</view>
		
	</view>
</template>

<script>
	const http = require('@/utils/http');
	export default {
		name: 'inquiry',
		props: {
			info: {
				type: Object,
				default: {}
			}
		},
		data() {
			return {
			
			}
		},
		mounted() {
			setTimeout(()=>{
				this.changeRadio(0)
			},100)
		},
		methods:{
			changeName(e){
				this.$emit('changeName',e.detail.value)
			},
			changeRadio(index){
				this.$emit('changeRadio',index)
			},
			upImgArr(){
				const that = this
				uni.chooseImage({
					count: '9',
					sizeType: ['original'],
					success(res) {
						uni.showLoading({
							title: '上传中'
						});
						for (let j = 0; j < res.tempFilePaths.length; j++) {
							http.upLoadFile('base/uploadImg', 'image', res.tempFilePaths[j], {}).then((res) => {
								that.$emit('drawing',res.data.url)
								uni.hideLoading();
							}).catch((res) => {
								uni.hideLoading();
								uni.showToast({
									title: res.message,
									icon: 'none'
								});
							});
						}
					},
					fail() {
						uni.hideLoading();
					}
				});
			},
			upFile(){
				const that = this
				uni.getSystemInfo({
					success: (res) => {
						if (res.platform == 'android' || res.platform == 'ios') {
							uni.chooseMessageFile({
								count: 9,
								type: 'file',
								success(res) {
									uni.showLoading({
										title: '上传中'
									});
									let up_length = 0;
									let list_length = res.tempFiles.length;
									for (let j = 0; j < res.tempFiles.length; j++) {
										let tempFiles = res.tempFiles[j];
										http.upLoadFile('base/getFile', 'file', tempFiles.path, {})
											.then((res) => {
												up_length = up_length + 1;
												const data = {
													name:tempFiles.name,
													url:res.data.file
												}
												that.$emit('fileName',data)
												if (up_length == list_length) {
													uni.hideLoading();
												}
											}).catch((res) => {
												uni.hideLoading();
												uni.showToast({
													title: res.message,
													icon: 'none'
												});
											});
									}
								},
								fail(res) {
									uni.hideLoading();
								}
							});
						} else {
							that.$emit('showToasts',true)
						}
					}
				});
			},
			onDelFile(index){
				this.$emit('delete',{name:'file',index:index})
			},
			onDel(index){
				this.$emit('delete',{name:'img',index:index})
			},
			onSub(){
				this.$emit('onSub')
			},
		}
	}
</script>

<style lang="scss">
	.inquiry {
		padding: 30rpx;
		height: 700rpx;
		position: relative;

		.cc {
			color: #ccc;
		}

		
	}
	scroll-view::-webkit-scrollbar,
	view::-webkit-scrollbar{
		display: none;
		width: 0;
		height: 0;
		color: transparent;
	}
</style>